package cn.eaay.stock.controller;

import cn.eaay.stock.service.StockBlockRtInfoService;
import cn.eaay.stock.service.StockService;
import cn.eaay.stock.vo.resp.PageResult;
import cn.eaay.stock.vo.resp.R;
import cn.eaay.stock.vo.stock.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 股票大盘Controller
 */
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Resource
    private StockService stockService;

    @Resource
    private StockBlockRtInfoService stockBlockRtInfoService;

    /**
     * 获取国内大盘最新数据详情
     *
     * @return {@link R<List<StockMarketIndexInfoVo> 大盘指数详情列表> }
     */
    @GetMapping("/index/all")
    public R<List<StockMarketIndexInfoVo>> getInnerStockMarket() {
        return stockService.getInnerSocketMarket();
    }

    /**
     * 获取国外大盘指数
     *
     * @return
     */
    @GetMapping("/external/index")
    public R<List<StockOuterMarketIndexVo>> getOuterStockMarket() {
        return stockService.getOuterStockMarket();
    }

    /**
     * 获取国内大盘板块实时数据详情
     *
     * @return {@link R<List<StockBlockInfoVo>> 大盘板块详情列表}
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockInfoVo>> getSectorAll() {
        return stockBlockRtInfoService.getSectorAllLimit();
    }

    /**
     * 获取个股涨幅分时行情数据
     *
     * @return
     */
    @GetMapping("/stock/increase")
    public R<List<StockRtInfoVo>> getStockIncrease() {
        return stockService.getStockIncrease();
    }

    /**
     * 获取个股行情列表，分页查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult> getStockAll(Integer page, Integer pageSize) {
        return stockService.getStockAll(page, pageSize);
    }

    /**
     * 查询涨停跌停数
     *
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<StockUpDownLimitVo> getStockUpDownCount() {
        return stockService.getStockUpDownLimitCount();
    }

    @GetMapping("/stock/export")
    public void exPort(HttpServletResponse response, Integer page, Integer pageSize) throws IOException {
        this.stockService.exportStockExcel(response, page, pageSize);
    }

    /**
     * 成交量对比
     *
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map> getStockTradeVolumeCompare() {
        return stockService.getStockTradeVolumeCompare();
    }

    /**
     * 获取单只股票每日K线数据
     * 日K线包含：今日最高价、今日最低价、开盘价、前收盘价
     *
     * @param stockCode 股票编码
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    public R<List<Map>> getDayLineData(@RequestParam("code") String stockCode) {
        return stockService.getDayKLinData(stockCode);
    }

    /**
     * 获取每分钟个股分时K线行情
     *
     * @param stockCode 股票编码
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Map>> getStockRtInfoByCode4EvrMinute(@RequestParam("code") String stockCode) {
        return stockService.getStockScreenMinuteSharing(stockCode);
    }

    /**
     * 统计当前时间下股票的涨跌幅度在各个区间的数量
     * 如果当前时间不在有效交易日内，则以最近的一个股票交易日作为查询点
     *
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown() {
        return stockService.getUpDownScope();
    }
}
